import {
	createApp
} from 'vue';
import dialogConstructor from './customDialog.vue'

let createMount = (opts) => {
	// 创建节点
	const mountNode = document.createElement('div')
	document.body.appendChild(mountNode)

	//创建实例 第一个参数是组件,第二个参数是传参Props里面的
	const app = createApp(dialogConstructor, {
		// 参数
		...opts,
		// 去除挂载与删除节点
		remove() {
			app.unmount(mountNode)
			document.body.removeChild(mountNode)
		}
	})
	//挂载到节点上
	return app.mount(mountNode)
}

function myDialog(options = {}) {
	createMount(options)
}

myDialog.install = app => {
	app.component('myDialog', dialogConstructor)
	// 两种全局挂载方法
	app.config.globalProperties.$myDialog = myDialog
	// app.provide('myDialog', myDialog)
}

export default myDialog
